﻿package com.xeem.henkel.st
{
	import com.adobe.images.*;
	import com.greensock.*;
	import com.greensock.easing.*;
	import com.xeem.core.utils.*;
	import com.xeem.henkel.common.*;
	import com.xeem.henkel.st.CraftModel;

	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.FileReference;
	import flash.printing.*;
	import flash.text.*;

	import org.alivepdf.display.Display;
	import org.alivepdf.layout.Mode;
	import org.alivepdf.layout.Orientation;
	import org.alivepdf.layout.Position;
	import org.alivepdf.layout.Resize;
	import org.alivepdf.layout.Unit;
	import org.alivepdf.pdf.PDF;
	import org.alivepdf.saving.Method;
	import org.alivepdf.images.ImageFormat;

	public class Crafts extends MovieClip
	{
		private var styler:NumberFormat=new NumberFormat();

		private var aryCC:Array = new Array(3);
		private var aryHC:Array = new Array(3);

		private var _bar:Sprite;


		public function Crafts()
		{
			init();
			initData();
			trace("Hello");
		}

		private function init()
		{

			var tf:TextFormat = new TextFormat();
			tf.size = 12;
			//tf.bold = true;
			tf.font = "Arial";
			//tf.color=0x008CD6;
			var tf1:TextFormat = new TextFormat();
			tf1.size = 12;
			tf1.bold = true;
			tf1.font = "Arial";
			tf1.color = 0xff0000;

			var tf2:TextFormat = new TextFormat();
			tf2.size = 10;
			//tf2.bold = true;
			tf2.font = "Arial";

			var tf3:TextFormat = new TextFormat();
			tf3.size = 12;
			tf3.bold = true;
			tf3.font = "Arial";

			cc1.addItem({data:"OEM",label:"OEM原厂制造"});
			cc1.addItem({data:"Supply",label:"Supply部件供应商"});
			cc1.addItem({data:"Others",label:"Others其他"});
			cc1.textField.setStyle("textFormat", tf);
			cc1.dropdown.setRendererStyle("textFormat", tf);

			ct1.setStyle("textFormat", tf);

			cc2.addItem({data:"hc",label:"Bonderite HC-1"});
			cc2.addItem({data:"cc",label:"Bonderite CC"});
			cc2.textField.setStyle("textFormat", tf);
			cc2.dropdown.setRendererStyle("textFormat", tf);
			cc2.addEventListener(Event.CHANGE,onChange);
			

			cc4.addItem({data:"蒸  汽",label:"蒸  汽"});
			cc4.addItem({data:"天燃气",label:"天燃气"});
			cc4.addItem({data:"柴  油",label:"柴  油"});
			cc4.addItem({data:"电  力",label:"电  力"});
			cc4.textField.setStyle("textFormat", tf);
			cc4.dropdown.setRendererStyle("textFormat", tf);
			cc4.addEventListener(Event.CHANGE,onChange);


			cc6.addItem({data:"铁系磷化",label:"铁系磷化"});
			cc6.addItem({data:"锌系磷化",label:"锌系磷化"});
			cc6.addItem({data:"硅烷工艺",label:"硅烷工艺"});
			cc6.textField.setStyle("textFormat", tf);
			cc6.dropdown.setRendererStyle("textFormat", tf);
			cc6.addEventListener(Event.CHANGE,onChange);

			ct2.setStyle("textFormat", tf);
			ct2.setStyle("textFormat", tf);
			ct3.setStyle("textFormat", tf2);
			ct4.setStyle("textFormat", tf);
			ct5.setStyle("textFormat", tf2);
			ct6.setStyle("textFormat", tf);
			ct6.addEventListener(Event.CHANGE,onChangeText);
			
			var tf5:TextFormat = new TextFormat();
			tf5.size = 12;
			tf5.font = "Arial";
			tf5.color=0xffffff;
			p00.setStyle("textFormat", tf5);

			p11.setStyle("textFormat", tf);
			p11.restrict = "0-9//.";
			p11.addEventListener(Event.CHANGE,onChange);
			p12.setStyle("textFormat", tf);
			p12.restrict = "0-9//.";
			p12.addEventListener(Event.CHANGE,onChange);
			p13.setStyle("textFormat", tf);
			p13.restrict = "0-9//.";
			p13.addEventListener(Event.CHANGE,onChange);
			p14.setStyle("textFormat", tf3);
			p15.setStyle("textFormat", tf1);



			p41.setStyle("textFormat", tf);
			p41.restrict = "0-9//.";
			p41.addEventListener(Event.CHANGE,onChange);
			p42.setStyle("textFormat", tf);
			p42.restrict = "0-9//.";
			p42.addEventListener(Event.CHANGE,onChange);
			p44.setStyle("textFormat", tf3);
			p45.setStyle("textFormat", tf1);

			p51.setStyle("textFormat", tf);
			p51.restrict = "0-9//.";
			p51.addEventListener(Event.CHANGE,onChange);
			p52.setStyle("textFormat", tf);
			p52.restrict = "0-9//.";
			p52.addEventListener(Event.CHANGE,onChange);
			p54.setStyle("textFormat", tf3);
			p55.setStyle("textFormat", tf1);
			/*
			p61.setStyle("textFormat", tf);
			p61.restrict = "0-9//.";
			p61.addEventListener(Event.CHANGE,onChange);
			p62.setStyle("textFormat", tf);
			p62.restrict = "0-9//.";
			p62.addEventListener(Event.CHANGE,onChange);
			p64.setStyle("textFormat", tf3);
			p65.setStyle("textFormat", tf1);
			*/
			p71.setStyle("textFormat", tf);
			p71.restrict = "0-9//.";
			p71.addEventListener(Event.CHANGE,onChange);
			p72.setStyle("textFormat", tf);
			p72.restrict = "0-9//.";
			p72.addEventListener(Event.CHANGE,onChange);
			p74.setStyle("textFormat", tf3);
			p75.setStyle("textFormat", tf1);
			/*
			p81.setStyle("textFormat", tf);
			p81.restrict = "0-9//.";
			p81.addEventListener(Event.CHANGE,onChange);
			p82.setStyle("textFormat", tf);
			p82.restrict = "0-9//.";
			p82.addEventListener(Event.CHANGE,onChange);
			p84.setStyle("textFormat", tf3);
			p85.setStyle("textFormat", tf1);			
			p91.setStyle("textFormat", tf);
			p91.restrict = "0-9//.";
			p91.addEventListener(Event.CHANGE,onChange);			
			p92.setStyle("textFormat", tf);
			p92.restrict = "0-9//.";
			p92.addEventListener(Event.CHANGE,onChange);
			*/
			p90.setStyle("textFormat", tf);
			p90.restrict = "0-9//.";
			p90.addEventListener(Event.CHANGE,onChange);
			p93.setStyle("textFormat", tf);
			p93.restrict = "0-9//.";
			p93.addEventListener(Event.CHANGE,onChange);

			//p96.setStyle("textFormat", tf);
			//p96.restrict = "0-9//.";
			//p96.addEventListener(Event.CHANGE,onChange);

			p941.setStyle("textFormat", tf3);
			p951.setStyle("textFormat", tf1);
			//p942.setStyle("textFormat", tf3);
			//p952.setStyle("textFormat", tf1);


			p04.setStyle("textFormat", tf3);
			p05.setStyle("textFormat", tf1);

			t01.setStyle("textFormat", tf3);
			t02.setStyle("textFormat", tf3);
			
			var tf4:TextFormat = new TextFormat();
			tf4.size = 12;
			tf4.bold = true;
			tf4.font = "Arial";
			tf4.align ="right";
			
			var tf6:TextFormat = new TextFormat();
			tf6.size = 12;
			tf6.font = "微软雅黑";
			tf6.letterSpacing=0.5;
			b04.setStyle("textFormat", tf6);
			b10.setStyle("textFormat", tf6);
			b11.setStyle("textFormat", tf6);
			b12.setStyle("textFormat", tf6);
			
			y1.setStyle("textFormat", tf4);
			y1.text="1";
			y2.setStyle("textFormat", tf4);
			y2.text="2";
			y3.setStyle("textFormat", tf4);
			y3.text="3";
			y4.setStyle("textFormat", tf4);
			y4.text="4";
			y5.setStyle("textFormat", tf4);
			y5.text="5";
			y6.setStyle("textFormat", tf4);
			y6.text="6";
			
			tp1.addEventListener(MouseEvent.CLICK,onSave);
			tp2.addEventListener(MouseEvent.CLICK,onPrint);
			


			/*v0.text = "";
			v1.text = "";
			v2.text = "";
			v3.text = "";
			v4.text = "";*/
		}

		private function initData()
		{

			var m0:CraftModel=new CraftModel();
			m0.Style = "cc";
			m0.Customer = "铁系磷化";
			m0.r0 = 0.3;
			m0.r1 = 0.4;
			m0.r2 = 0.17;
			m0.r3 = 1;
			m0.r40 = 1;
			m0.r41 = 1;
			aryCC[0] = m0;

			var m1:CraftModel=new CraftModel();
			m1.Style = "cc";
			m1.Customer = "锌系磷化";
			m1.r0 = 0.25;
			m1.r1 = 0.3;
			m1.r2 = 0.07;
			m1.r3 = 1.2;
			m1.r40 = 1;
			m1.r41 = 1 ;
			aryCC[1] = m1;

			var m2:CraftModel=new CraftModel();
			m2.Style = "cc";
			m2.Customer = "硅烷工艺";
			m2.r0 = 0.35;
			m2.r1 = 1.1;
			m2.r2 = 3;
			m2.r3 = 1.7;
			m2.r40 = 0;
			m2.r41 = 0;
			aryCC[2] = m2;


			var m3:CraftModel=new CraftModel();
			m3.Style = "hc";
			m3.Customer = "铁系磷化";
			m3.r0 = 0.3;
			m3.r1 = 0.35;
			m3.r2 = 0.05;
			m3.r3 = 1.5;
			m3.r40 = 1;
			m3.r41 = 1 ;
			aryHC[0] = m3;

			var m4:CraftModel=new CraftModel();
			m4.Style = "hc";
			m4.Customer = "锌系磷化";
			m4.r0 = 0.25;
			m4.r1 = 0.25;
			m4.r2 = 0.02;
			m4.r3 = 1.3;
			m4.r40 = 1;
			m4.r41 = 1;
			aryHC[1] = m4;

			var m5:CraftModel=new CraftModel();
			m5.Style = "hc";
			m5.Customer = "硅烷工艺";
			m5.r0 = 0.35;
			m5.r1 = 1;
			m5.r2 = 1;
			m5.r3 = 0.9;
			m5.r40 = 0;
			m5.r41 = 0;
			aryHC[2] = m5;

		}

		private function getRate(ary:Array,s:String,pos:Number):Number
		{
			for (var i:int=0; i<ary.length; i++)
			{
				if (ary[i].Customer == s)
				{
					if (pos==0)
					{
						return ary[i].r0;
					}
					if (pos==1)
					{
						return ary[i].r1;
					}
					if (pos==2)
					{
						return ary[i].r2;
					}
					if (pos==3)
					{
						return ary[i].r3;
					}
					if (pos==4)
					{
						return ary[i].r40;
					}
					if (pos==5)
					{
						return ary[i].r41;
					}
				}
			}
			return -1;
		}


		private function round(x:Number,p:int):Number
		{
			if (p==0)
			{
				return Math.round(x);
			}
			else
			{
				return Math.round(x*Math.pow(10,p))/Math.pow(10,p);
			}
		}

		private function getVal(val:String):Number
		{
			if (isNaN(Number(val.split(",").join(""))))
			{
				return 0;
			}
			return Number(val);
		}

		private function onChangeText(e:Event):void
		{
			p00.text = ct6.text;
		}

		private function onChange(e:Event):void
		{
			var tf:TextFormat = new TextFormat();
			tf.size = 12;
			//tf.bold = true;
			tf.font = "Arial";
			//tf.color=0x008CD6;			
			if (cc4.selectedItem.data=="蒸  汽"){
				l1.htmlText="元/吨";
				l2.htmlText="吨";
				l3.htmlText="天";
			}
			if (cc4.selectedItem.data=="天燃气"){
				l1.htmlText="元/M<sup>3</sup>";
				l2.htmlText="M<SUP>3</SUP>";
				l3.htmlText="天";
			}
			if (cc4.selectedItem.data=="柴  油"){
				l1.htmlText="元/吨";
				l2.htmlText="吨";
				l3.htmlText="天";
			}
			if (cc4.selectedItem.data=="电  力"){
				l1.htmlText="元/度";
				l2.htmlText="度";
				l3.htmlText="天";
			}
			
			//
			if (cc6.selectedItem.data == "硅烷工艺" )
				b04.text="硅烷工艺需要增加一套隔膜泵装置和加热装置，成本约5万元";
		    b10.text=cc6.selectedItem.data;
			//工艺
			if (cc2.selectedItem.data == "hc")
			{				
				b11.text="Bonderite HC-1";
				b12.text="Bonderite HC-1";
				ZZ(aryHC);
			}

			if (cc2.selectedItem.data == "cc")
			{				
			 
				b11.text="Bonderite CC";
				b12.text="Bonderite CC";
				ZZ(aryCC);
			}

		}

		private function ZZ(ary:Array)
		{

			var n04:Number;
			var n0401:Number;
			var n0402:Number;
			var n0403:Number;
			var n0404:Number;
			var n0405:Number;
			var n05:Number;
			var n0501:Number;
			var n0502:Number;
			var n0503:Number;
			var n0504:Number;
			var n0505:Number;

			var n4:Array = new Array(6);
			var n5:Array = new Array(6);

			var r0:Number;
			var r1:Number;
			var h:Number;
			var d:Number;

			var tf4:TextFormat = new TextFormat();
			tf4.size = 12;
			tf4.bold = true;
			tf4.font = "Arial";
			tf4.color = 0x310101;

			var tf5:TextFormat = new TextFormat();
			tf5.size = 12;
			tf5.bold = true;
			tf5.font = "Arial";
			tf5.color = 0xff0000;



			//能耗
			r0 = getRate(ary,cc6.selectedItem.data,0);
			p14.text=styler.format(round(getVal(p11.text)*getVal(p12.text)*getVal(p13.text)*12,2),new Locale("en","US")).toString();
			n04 = getVal(p11.text) * getVal(p12.text) * getVal(p13.text) * 12;
			p15.text=styler.format(round(getVal(p11.text)*getVal(p12.text)*getVal(p13.text)*12*r0,2),new Locale("en","US")).toString();
			n05 = n04 * r0;

			n0401 = n04;
			n0501 = n05;

			r0 = r1 = 0;

			r0 = getRate(ary,cc6.selectedItem.data,2);
			//废渣
			p44.text=styler.format(round(getVal(p41.text)*getVal(p42.text)*12,2),new Locale("en","US")).toString();
			n04 +=  getVal(p41.text) * getVal(p42.text) * 12;
			p45.text = styler.format(round(getVal(p41.text)*getVal(p42.text)*12*r0,2),new Locale("en","US")).toString();
			n05 +=  getVal(p41.text) * getVal(p42.text) * 12 * r0;

			n0405 = n04 - n0401;
			n0505 = n05 - n0501;

			//废水
			r1 = getRate(ary,cc6.selectedItem.data,1);
			p54.text=styler.format(round(getVal(p51.text)*getVal(p52.text)*12,2),new Locale("en","US")).toString();
			n04 +=  getVal(p51.text) * getVal(p52.text) * 12;
			p55.text=styler.format(round(getVal(p51.text)*getVal(p52.text)*12*r1,2),new Locale("en","US")).toString();
			n05 +=  getVal(p51.text) * getVal(p52.text) * 12 * r1;
			//p64.text=styler.format(round(getVal(p61.text)*getVal(p62.text)*12,2),new Locale("en","US")).toString();
			//n04 +=  getVal(p61.text) * getVal(p62.text) * 12;
			//p65.text="0";
			n0402 = n04 - n0401 - n0405;
			n0502 = n05 - n0501 - n0505;
			r0 = r1 = 0;

			r0 = getRate(ary,cc6.selectedItem.data,3);
			r1 = getRate(ary,cc6.selectedItem.data,4);
			
			//化学品
			var zzz:Number;
			zzz=getVal(p71.text)*12;			
			p74.text=styler.format(round(zzz,2),new Locale("en","US")).toString();
			n04 += zzz;
			p75.text=styler.format(round(zzz*r0,2),new Locale("en","US")).toString();
			n05 += zzz*r0;
			
			;
			/*
			p84.text=styler.format(round(getVal(p81.text)*getVal(p82.text)*12,2),new Locale("en","US")).toString();
			n04 +=  getVal(p81.text) * getVal(p82.text) * 12;
			p85.text=styler.format(round(getVal(p81.text)*getVal(p82.text)*12*0.9,2),new Locale("en","US")).toString();
			n05 +=  getVal(p81.text) * getVal(p82.text) * 12 * 0.9;
			*/
			n0403 = n04 - n0401 - n0402 - n0405;
			n0503 = n05 - n0501 - n0502 - n0505;

			r0 = r1 = 0;

			r0 = getRate(ary,cc6.selectedItem.data,5);
			r1 = getRate(ary,cc6.selectedItem.data,4);


			//维护成本
			var yyy:Number;
			yyy=getVal(p90.text)*12*r1;
			if (yyy<0) yyy=0;
			p941.text=styler.format(round(yyy,2),new Locale("en","US")).toString();
			n04 += yyy;
			yyy=getVal(p93.text)*12*r0;
			if (yyy<0) yyy=0;
			p951.text =styler.format(round(yyy,2),new Locale("en","US")).toString();
			n05 += yyy;

			n0404 = n04 - n0401 - n0402 - n0403 - n0405;
			n0504 = n05 - n0501 - n0502 - n0503 - n0505;


			p04.text = styler.format(round(n04,2),new Locale("en","US")).toString();
			p05.text = styler.format(round(n05,2),new Locale("en","US")).toString();

			n4[0] = n0403;
			n4[1] = n0402;
			n4[2] = n0401;
			n4[3] = n0405;
			n4[4] = n0404;
			n4[5] = n04;

			n5[0] = n0503;
			n5[1] = n0502;
			n5[2] = n0501;
			n5[3] = n0505;
			n5[4] = n0504;
			n5[5] = n05;
			
			t01.text= styler.format(round(n05-n04,2),new Locale("en","US"));
			if (n04>0){t02.text= styler.format(round((n05/n04-1)*100,2),new Locale("en","US")).toString()+"%";}
			if (n05>0 || n04>0)
			{
				drawChar(n4,n5,740,110);
			}
		}

		private function drawChar(n4:Array,n5:Array,x:Number,y:Number):void
		{
			
			var t0:Number = n4[5];
			var t1:Number = n5[5];
			var o:Number=240;
			var w:Number=1;
			var mxx:Number = 240;
			var mxy:Number = 240;
			var v:Array = new Array(2);

			if (t0>t1)
			{
				w=int(t0/5);				
				if (t0%5==0) {
					o=210;
				}else {
					o=240;}
				mxx = o;
				mxy = o * t1 / t0;
				
				
			}
			else
			{
				w=int(t1/5);				
				if (t1%5==0){ 
					o=210;
				}else {
					o=240;
				}
				mxy = o;
				mxx = o * t0 / t1;
			}
			
			y1.text=styler.format(1*w,new Locale("en","US")).toString();
			y2.text=styler.format(2*w,new Locale("en","US")).toString();
			y3.text=styler.format(3*w,new Locale("en","US")).toString();
			y4.text=styler.format(4*w,new Locale("en","US")).toString();
			y5.text=styler.format(5*w,new Locale("en","US")).toString();
			y6.text=styler.format(6*w,new Locale("en","US")).toString();			
			
			
			_bar=new Sprite();
			_bar.graphics.beginFill(0xffffff,1);
			_bar.graphics.drawRect(0,0,300,240);
			_bar.graphics.endFill();
			_bar.x = x;
			_bar.y = y;

			
			v[0]=v[1]=240;
			
			//化学品			
			draw1(0x9999FF,n4[0],n5[0],t0,t1,v,mxx,mxy);

			//废水
			draw1(0xFF0000,n4[1],n5[1],t0,t1,v,mxx,mxy);

			//能耗;
			draw1(0xFFFF00,n4[2],n5[2],t0,t1,v,mxx,mxy);
			
			//废渣;
			draw1(0xCCFFFF,n4[3],n5[3],t0,t1,v,mxx,mxy);

			//维护;
			draw1(0xFF6600,n4[4],n5[4],t0,t1,v,mxx,mxy);
			
			addChild(_bar);
		}

		private function drawDashed(x0:Number,y0:Number,x1:Number,y1:Number,widths:Number,grap:Number):void
		{
			if (widths <= 0 || grap <= 0)
			{
				return;
			}
			var radian:Number = Math.atan2(y1 - y0,x1 - x0);
			var totalLen:Number = Point.distance(new Point(x0,y0),new Point(x1,y1));
			var currLen:Number = 0;
			var x:Number,y:Number;
			_bar.graphics.lineStyle(1,0x0);
			while (currLen <= totalLen)
			{
				x = x0 + Math.cos(radian) * currLen;
				y = y0 + Math.sin(radian) * currLen;
				_bar.graphics.moveTo(x,y);
				currLen +=  widths;
				if (currLen > totalLen)
				{
					currLen = totalLen;
				}

				x = x0 + Math.cos(radian) * currLen;
				y = y0 + Math.sin(radian) * currLen;
				
				_bar.graphics.lineTo(x,y);

				currLen +=  grap;
			}
		}

		private function draw1(color:Number,n4:Number,n5:Number,t0:Number,t1:Number,v:Array,mxx:Number,mxy:Number):void{
			
			var h:int=int(mxx*n4/t0);
			v[0] = v[0] - h;
			_bar.graphics.beginFill(color,1);
			_bar.graphics.drawRect(0,v[0],70,h);
			_bar.graphics.endFill();
			
			/*
			if (h>=12){
				s0=new TextField();
				s0.text=styler.format(round(n4,2),new Locale("en","US")).toString();
				s0.x=15;
				s0.y=v0+h/2;
				_bar.addChild(s0);
			}
			*/

			h=int(mxy*n5/t1);
			v[1] = v[1] - h;
			_bar.graphics.beginFill(color,1);
			_bar.graphics.drawRect(190,v[1],70,h);
			_bar.graphics.endFill();
			/*
			if (h>=12){
				d0=new TextField();
				d0.text=styler.format(round(n5,2),new Locale("en","US")).toString();
				d0.x=205;
				d0.y=v1+h/2;
				_bar.addChild(d0);
			}
			*/
			
			drawDashed(70,v[0],190,v[1],10,5);

			
		}
		
		private function onFormatData(e:FocusEvent):void
		{
			if (isNaN(e.currentTarget.text.split(",").join("")))
			{
				e.currentTarget.text = "0";
			}
			e.currentTarget.text = styler.format(Number(e.currentTarget.text.split(",").join("")),new Locale("en","US"));
			onChange(e);
		}

		private function onChangeData(e:FocusEvent):void
		{
			e.currentTarget.text = e.currentTarget.text.split(",").join("");
		}

		private function onPrint(e:MouseEvent):void
		{
			var printJob:PrintJob=new PrintJob();
			var printArea:Rectangle;
			if (! printJob.start())
			{
				return;
			}
			var bit:BitmapData = new BitmapData(600,858);
			var mat:Matrix= new Matrix(1,0,0,1,0,0);
			bit.draw(this,mat,null,null,new Rectangle(0,0,600,858));
			var bmap:Bitmap = new Bitmap(bit);
			var s:Sprite=new Sprite();
			s.addChild(bmap);
			s.width = printJob.pageWidth;
			s.height = printJob.pageHeight;
			s.scaleY = s.scaleX;
			printJob.addPage(s);
			mat=new Matrix(1,0,0,1,-600,0);
			var bit2:BitmapData = new BitmapData(600,858);
		    bit2.draw(this,mat,null,null,new Rectangle(0,0,600,858));
			bmap= new Bitmap(bit2);
			var s2:Sprite=new Sprite();
			s2.addChild(bmap);			
			s2.width = printJob.pageWidth;
			s2.height = printJob.pageHeight;
			s2.scaleY = s2.scaleX;
			printJob.addPage(s2);			
			printJob.send();
			/* Delete job from memory */
			printJob = null;

		}

		private function onSave(e:MouseEvent):void
		{
			var bit:BitmapData = new BitmapData(600,858);
			var mat:Matrix= new Matrix(1,0,0,1,0,0);
			bit.draw(this,mat,null,null,new Rectangle(0,0,600,858));
			var bmap:Bitmap = new Bitmap(bit);
			var s:Sprite=new Sprite();
			s.addChild(bmap);
			//var jpg:JPGEncoder = new JPGEncoder(100);
			var file:FileReference = new FileReference();
			//file.save(jpg.encode(bit),"henkel"+(new Date().fullYear*10000+(new Date().month+1)*100+new Date().date).toString()+".jpg");
			var myPDF:PDF = new PDF(Orientation.PORTRAIT,Unit.POINT);
			myPDF.addPage();
			myPDF.addImage(s, new Resize ( Mode.FIT_TO_PAGE, Position.CENTERED ));						
			mat=new Matrix(1,0,0,1,-600,0);
			var bit2:BitmapData = new BitmapData(600,858);
		    bit2.draw(this,mat,null,null,new Rectangle(0,0,600,858));
			bmap= new Bitmap(bit2);
			var s2:Sprite=new Sprite();
			s2.addChild(bmap);
			myPDF.addPage();
			myPDF.addImage(s2, new Resize ( Mode.FIT_TO_PAGE, Position.CENTERED ));
			file.save(myPDF.save(Method.LOCAL ),"henkel-st"+(new Date().fullYear*10000+(new Date().month+1)*100+new Date().date).toString()+".pdf");
		}

	}

}